package com.example.musicgui.controller;

import com.example.musicgui.client.MusicClient;
import com.example.musicgui.model.ResponseBodyMessage;
import com.example.musicgui.model.User;
import com.example.musicgui.tools.ObjuctOrJSON;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class UserController {
    private ObjuctOrJSON<String> json = new ObjuctOrJSON<>();
    private ResponseBodyMessage<String> message;
    public ResponseBodyMessage<String> login(User user) throws Exception {
         return json.User(new MusicClient().start(ObjuctOrJSON.toJSON(userMap(user,"login"))));
    }
    public ResponseBodyMessage<String> sign(User user) throws Exception {
        return json.User(new MusicClient().start(ObjuctOrJSON.toJSON(userMap(user,"sign"))));
    }
    private Map<String,String> userMap(User user,String type){
        Map<String,String> userMap = new HashMap<>();
        userMap.put("type",type);
        userMap.put("username",user.getUsername());
        userMap.put("password",user.getPassword());
        return userMap;
    }
}
